<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..." v-model="queryParam.ksbh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{i.dwh+'-'+ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkzydm" @change='zyChange'>
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh +'-'+ i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="研究方向">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyjfxm">
                 <a-select-option v-for="i in selectMenu.yjfx" :key="i.id" :value="i.yjfxm">{{ i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学习形式">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zhxlxxxs">
                <a-select-option v-for="i in selectMenu.xxlx" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目一">
               <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zzllcjfw">
                    <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.zzllcj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目二">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.wgycjfw">
                    <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.wgycj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目三">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ywkycjfw">
                    <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ywkycj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目四">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ywkecjfw">
                    <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ywkecj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="总成绩">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.cszcjfw">
                    <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.cszcj"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专项计划生">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zxjh">
                 <a-select-option v-for="i in zxjhs" :key="i.id" :value="i.id">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="考生类型">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.kslx">
                 <a-select-option v-for="i in kslx" :key="i.id" :value="i.id">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:20}" :xl="{span:10}">
            <span class="table-page-search-submitButtons" >
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatchApply">批量申请</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :pagination="pagination"
       @change="handleTableChange"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  <!-- 审查 -->
  <abnormality-apply @close="handleApplyClose" @success="handleApplySuccess" :abnormalityApplyVisible="abnormalityApplyVisible" :selectedIds='selectedIds'></abnormality-apply>
    </a-card>
</div>
</template>

<script>
import AbnormalityApply from './abnormalityApply'
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    AbnormalityApply
  },
  data () {
    return {
      advanced: true,
      abnormalityApplyVisible: false,
      loading: false,
      data: [],
      scoreList:['<=','>='],
      // 查询参数
      queryParam: {
        bkyjfxm:'',
        bkyxsm:'',
        bkzydm:'',
        cszcj:'',
        cszcjfw:'',
        ksbh:'',
        ksxm:'',
        wgycj:'',
        wgycjfw:'',
        ywkecj:'',
        ywkecjfw:'',
        ywkycj:'',
        ywkycjfw:'',
        zhxlxxxs:'',
        zzllcj:'',
        zzllcjfw:'',
        ksbh:'',
        zsxn:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
           title: '准考证号',
           dataIndex: 'ksbh'
         },
         {
           title: '姓名',
           dataIndex: 'ksxm'
         },
         {
           title: '报考院系',
           dataIndex: 'bkyxsmc'
         },
         {
           title: '报考专业代码',
           dataIndex: 'bkzydm'
         },
         {
           title: '报考专业',
           dataIndex: 'bkzymc'
         },
         {
           title: '研究方向',
           dataIndex: 'bkyjfxmc'
         },
         {
           title: '科目一',
           dataIndex: 'zzllcj'
         },
         {
           title: '科目二',
           dataIndex: 'wgycj'
         },
         {
           title: '科目三',
           dataIndex: 'ywkycj'
         },
         {
           title: '科目四',
           dataIndex: 'ywkecj'
         },
         {
           title: '总分',
           dataIndex: 'zf'
         },
        // {
        //   title: '上线状态',
        //   dataIndex: 'sxzt'
        // }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [] ,// 院系
        zy:[] ,
        xxlx:[],
        kslxlb:[],
        sjplfs:[],
        yjfx:[]
      },
      planReviewData: {},
      selectedRowKeys:[],
      selectedRows:[],
       pagination:{
        current:1
      },
      newParams:{},
      selectedIds:'',
      zxjhs:[
        {
          id:'0',
          name:'否'
        },
        {
          id:'1',
          name:'是'
        }

      ],
      kslx:[
        {
          id:'01',
          name:' 一志愿考生'
        },
        {
          id:'02',
          name:'二志愿考生'
        },
        {
          id:'06',
          name:'考生成绩查询'
        }
      ]
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    // this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.queryParam.wgycjfw = this.queryParam.ywkycjfw = this.queryParam.ywkecjfw =
    this.queryParam.cszcjfw = this.queryParam.zzllcjfw   = this.scoreList[0]
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
          // 获取当前学年
        this.$api.base.getSchoolYear().then(res=>{
          this.queryParam.zsxn = res.data.masterAdmissionYear
        })
           // 获取学习形式
        this.$api.base.dictionaryData('TYPE0441').then(res => {
        	this.selectMenu.xxlx = res.data
        })
        this.queryParam.bkyxsm = res[0].data[0].dwh
        this.getProssion(this.queryParam.bkyxsm)
        this.loadData({
          pageSize: 10,
          pageNum: 1
        })
      })
    },
         // 加载数据
    loadData (parameter = {}) {
      if(!parameter.pageNum){
        this.pagination.current = 1
        parameter.pageNum = 1
      }
      this.getParams()
      let params = Object.assign(this.newParams, parameter)
      this.loading = true
        this.$api.recruitstat.reExamBreakMangageList(params).then(res=>{
              const pagination = { ...this.pagination
            };
            pagination.total = 0
            if (res.data && res.data.total) {
              pagination.total = res.data.total;
            }
            this.data = []
            this.pagination = pagination;
            if (res.data && res.data.rows && res.data.rows.length) {
              this.data = res.data.rows;
            }
            this.loading = false;
        })
    },
    getParams(){
       this.newParams = {}
      for(var item in this.queryParam){
        if(item != 'zzllcjfw' && item != 'wgycjfw' && item != 'ywkycjfw' && item != 'ywkecjfw' && item != 'cszcjfw' ){
          this.newParams[item] = this.queryParam[item]
        }
      }

      this.queryParam.zzllcj? (this.queryParam.zzllcjfw =='>=' ? this.newParams.zzllcjd = '01' :this.newParams.zzllcjx = '01'):''
      this.newParams.wgycj ?  (this.queryParam.wgycjfw =='>=' ? this.newParams.wgycjd = '01' :this.newParams.wgycjx = '01'):''
      this.newParams.ywkycj ?  (this.queryParam.ywkycjfw =='>=' ? this.newParams.ywkycjd = '01' :this.newParams.ywkycjx = '01'):''
      this.newParams.ywkecj ?  (this.queryParam.ywkecjfw =='>=' ? this.newParams.ywkecjd = '01' :this.newParams.ywkecjx = '01'):''
      this.newParams.cszcj ?  (this.queryParam.cszcjfw =='>=' ? this.newParams.cszcjd = '01' :this.newParams.cszcjx = '01'):''
    },
    // 分页
    handleTableChange (pagination, filters, sorter) {
     console.log(pagination);
     const pager = { ...this.pagination };
     pager.current = pagination.current;
     this.pagination = pager;
     this.loadData({
       pageSize: 10,
       pageNum: pager.current
     });
    },
       // 多选
   onSelectChange (selectedRowKeys,selectedRows) {
     console.log('selectedRowKeys changed: ', selectedRowKeys);
     this.selectedRows = selectedRows
     this.selectedRowKeys = selectedRowKeys
   },
   // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'bkzydm', '')
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.selectMenu, 'zy', [])
      this.$set(this.selectMenu, 'yjfx', [])
      if(code){
       this.getProssion(code)
      }
    },
    getProssion(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
     // 选择专业
    zyChange(code){
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.selectMenu, 'yjfx', [])
      if(code){
        this.getDurection(code)
      }
    },
    getDurection(code){
      this.$api.base.searchDirectory({
        ssyxm: this.queryParam.bkyxsm,
        zsxn:this.queryParam.zsxn,
        sszym: code,
         xwccm: 2
      }).then(res => {
        this.$set(this.selectMenu, 'yjfx', res.data)
      })
    },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      console.log('导出')
      this.getParams()
      this.$export('admissions/fspgg/export',this.newParams)
    },
    // 批量申请
    handleBatchApply () {
      var deleteId = ''
      if(!this.selectedRowKeys.length){
        this.$message.warn('请选择要申请的数据')
        return ;
      }
      if(this.selectedRows && this.selectedRows.length){
        deleteId = this.selectedRows.map(v => {
          return v.id
        }).toString()
      }
      this.selectedIds = deleteId;
      // var that = this
      // this.$confirm({
      //   title: '确定批量申请?',
      //   onOk() {
      //     console.log('OK');
      //     that.$api.recruitstat.reExamBreakMangageMulCheck(deleteId).then( res => {
      //       that.loadData({
      //         pageSize: 10,
      //         pageNum: that.pagination.current
      //       });
      //       that.selectedRowKeys = []
      //     })
      //   },
      //   onCancel() {
      //     console.log('Cancel');
      //   },
      //   class: 'test',
      // });
        this.abnormalityApplyVisible = true

    },
    // 取消录取
    handleApplyClose (data) {
      this.abnormalityApplyVisible = false
    },
    // 提交
    handleApplySuccess () {
      this.abnormalityApplyVisible = false
      this.loadData({
        pageSize: 10,
        pageNum: this.pagination.current
      });
      this.selectedRowKeys = []
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
